cmake_minimum_required(VERSION 3.10)
project(cpp_mlweb)

# 禁用编译器ID文件生成
set(CMAKE_COMPILER_ID_FILE OFF)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找必要的包
find_package(Crow REQUIRED)
find_package(Threads REQUIRED)

# 查找jsoncpp
find_library(JSONCPP_LIBRARY NAMES jsoncpp)
find_path(JSONCPP_INCLUDE_DIR json/json.h
    PATHS /usr/include/jsoncpp /usr/local/include/jsoncpp)

if(NOT JSONCPP_LIBRARY OR NOT JSONCPP_INCLUDE_DIR)
    message(FATAL_ERROR "jsoncpp not found")
endif()

# 查找MySQL
find_path(MYSQL_INCLUDE_DIR mysql.h
    PATHS /usr/include/mysql /usr/local/include/mysql)
find_library(MYSQL_LIBRARY NAMES mysqlclient
    PATHS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)

if(NOT MYSQL_INCLUDE_DIR OR NOT MYSQL_LIBRARY)
    message(FATAL_ERROR "MySQL not found")
endif()

# 添加头文件目录
include_directories(
    ${CMAKE_SOURCE_DIR}
    ${CROW_INCLUDE_DIRS}
    ${MYSQL_INCLUDE_DIR}
    ${JSONCPP_INCLUDE_DIR}
)

# 明确列出所有源文件
set(SOURCES
    main.cpp
    controllers/default.cpp
    models/cmd.cpp
    models/db_manager.cpp
    models/mod.cpp
    models/route.cpp
    models/route_change.cpp
    models/status.cpp
    models/version.cpp
    utils/ip_utils.cpp
    utils/session_manager.cpp
    utils/template_manager.cpp
)

# 创建可执行文件
add_executable(cpp_mlweb ${SOURCES})

# 链接库
target_link_libraries(cpp_mlweb
    ${CROW_LIBRARIES}
    ${MYSQL_LIBRARY}
    ${JSONCPP_LIBRARY}
    Threads::Threads
) 